package com.wc.codeforces.DP.状态机.Magnitude_Easy_Version;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/7/19 23:38
 * @description https://codeforces.com/problemset/problem/1984/C1
 */
public class Main {
    /**
     * 思路：
     * 动态规划，一共就两个状态, 最大值，最小值，因为最小值是可以绝对值之后转换为最大值
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] a = new int[N];
    /**
     * f[i][0] 表示该数与前面的数相加的最大值
     * f[i][1] 表示该数与前面的数相加绝对值的最大值
     * f[i][2] 表示该数与前面的数相加的最小值
     * f[i][3] 表示该数与前面的数相加绝对值的最小值
     */
    static long[][] f = new long[N][4];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            for (int i = 1; i <= n; i++) {
                long max1 = Math.max(f[i - 1][0] + a[i], f[i - 1][1] + a[i]);
                long max2 = Math.max(f[i - 1][2] + a[i], f[i - 1][3] + a[i]);
                f[i][0] = Math.max(max1, max2);
                max1 = Math.max(Math.abs(f[i - 1][0] + a[i]), Math.abs(f[i - 1][1] + a[i]));
                max2 = Math.max(Math.abs(f[i - 1][2] + a[i]), Math.abs(f[i - 1][3] + a[i]));
                f[i][1] = Math.max(max1, max2);
                long min1 = Math.min(f[i - 1][0] + a[i], f[i - 1][1] + a[i]);
                long min2 = Math.min(f[i - 1][2] + a[i], f[i - 1][3] + a[i]);
                f[i][2] = Math.min(min1, min2);
                min1 = Math.min(Math.abs(f[i - 1][0] + a[i]), Math.abs(f[i - 1][1] + a[i]));
                min2 = Math.min(Math.abs(f[i - 1][2] + a[i]), Math.abs(f[i - 1][3] + a[i]));
                f[i][3] = Math.min(min1, min2);
            }
            out.println(Math.max(f[n][0], f[n][1]));
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
